﻿using Entity;
using IRealize;
using Microsoft.AspNetCore.Mvc;
using Realize;
using System.Collections.Generic;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace WebApplication9.Controllers.Comp_Stand_m
{
    public class SS_SearchController : Controller
    {
        private readonly ILogger<SS_SearchController> _logger;
        private readonly IConfiguration configuration;

        public SS_SearchController(ILogger<SS_SearchController> logger, IConfiguration configuration)
        {
            this._logger = logger;
            this.configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> Index2(string bh, string Name, DateTime datak, DateTime dataj,int i, int p)
        {
            ISS ss = new SS();
            List<Salary_Standard> zhi = await ss.Server3(configuration["SqlServer"]);
            List<Salary_Standard> zhi3 = zhi.ToList();
            if (bh != null && bh != "" && bh != "undefined")
            {
                zhi3 = zhi3.Where(e=>e.standard_id.Contains(bh)).ToList();
            }
            if (Name != null && Name!="" && Name != "undefined")
            {
                zhi3 = zhi3.Where(e=>e.standard_name.Contains(Name)).ToList();
            }
            if (datak != DateTime.MinValue && dataj != DateTime.MinValue)
            {
                zhi3 = zhi3.Where(e => e.regist_time >= datak).ToList();
                zhi3 = zhi3.Where(e => e.regist_time <= dataj).ToList();
            }
            List<Salary_Standard> zhi2 = zhi3.Skip((i - 1) * p).Take(p).ToList();
            PagedViewModel<Salary_Standard> cc = new PagedViewModel<Salary_Standard>() { itemas = zhi2, total = zhi3.Count };
            return Ok(new
            {
                list = cc
            });
        }
        public async Task<IActionResult> Index3(string s_id)
        {
            ISS ss = new SS();
            List<Salary_Standard> list = await ss.Server2(s_id, configuration["SqlServer"]);
            return Ok(new
            {
                zhi = list[0]
            });
        }
        public async Task<IActionResult> Server2(string s_id)
        {
            ISSD ssd = new SSD();

            ViewBag.s_id = s_id;
            ViewBag.list = await ssd.Server3(s_id,configuration["SqlServer"]);
            ViewBag.list2 = "aaa";
            return View();
        }
        public async Task<IActionResult> Server(string bh,string Name,DateTime datak,DateTime dataj)
        {
            ViewBag.bh = bh;
            ViewBag.Name = Name;
            ViewBag.Datak = datak;
            ViewBag.Dataj = dataj;
            /*HttpContext.Session.SetString("bh", bh);
            HttpContext.Session.SetString("Name", Name);
            HttpContext.Session.SetString("Datak", datak.ToString());
            HttpContext.Session.SetString("Dataj", dataj.ToString());*/
            return View();
            //ISS ss = new SS();
            /*List<Salary_Standard> zhi = await ss.Server(configuration["SqlServer"]);
            List<Salary_Standard> zhi2 = zhi.Skip((i - 1) * p).Take(p).ToList();
            PagedViewModel<Salary_Standard> cc = new PagedViewModel<Salary_Standard>() { itemas = zhi2, total = zhi.Count };*/
        }
    }
}
